package com.aaa.jdbc.userinfo.impl;

import com.aaa.jdbc.BaseDao;
import com.aaa.jdbc.userinfo.UserInfo;
import com.aaa.jdbc.userinfo.UserInfoDao;

import java.util.List;
import java.util.Map;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/27 9:26
 * @description：用户dao的实现类
 * @modified By：
 * @version: 1.0
 */
public class UserInfoDaoImpl extends BaseDao implements UserInfoDao   {
    @Override
    public boolean saveUserInfo(UserInfo userInfo) {
        String sql="insert into userinfo (username,password,createtime,phone) values(?,?,?,?) ";
        return super.executeUpdate(sql,userInfo.getUsername(),userInfo.getPassword(),userInfo.getCreateTime(),userInfo.getPhone());
    }

    @Override
    public boolean deleteUserInfoById(Integer id) {
       String sql="delete from userinfo where id=?";
        return executeUpdate(sql,id);
    }

    @Override
    public int saveUserInfoKey(UserInfo userInfo) {
        String sql="insert into userinfo (username,password,createtime,phone) values(?,?,?,?) ";
        return super.executeUpdateKey(sql,userInfo.getUsername(),userInfo.getPassword(),userInfo.getCreateTime(),userInfo.getPhone());
    }

    @Override
    public List<Map<String, Object>> queryAll() {
        return executeQuery("select * from userinfo");
    }

    @Override
    public List<Map<String, Object>> queryAllByCondition(Map<String, Object> condition) {
        String sql="select * from userinfo where username=? and password =?";
        return executeQuery(sql,condition.get("username"),condition.get("password"));
    }
}
